﻿/**
 *	html/monitor/center/scene/panel_event.js
 *
 *	(C) 2014 Yuanjj
 *
 * 	history:
 * 		2014-07-21			create the file
 */

/**
 *	create the event panel
 *
 *	@panel_center		[in] the center panel object
 *	@showflag			[in] the show flag ( "show" or "hide" )
 *
 *	return
 *		void
 */
function create_event_panel( panel_center, showflag )
{
    var panel = new Ext.panel.Panel
    ({
         id:"panel_c_event",
         layout:"vbox",
         flex:1,
         width:"100%",
         listeners:{ afterrender:_create_event_component }
    });

    if ( "show" === showflag )
        panel.show();
    else
        panel.hide();

    panel_center.add_subpanel( panel );
}

/**
 *	create the components for event
 *
 *	@panel_c_event		[in] the event panel object
 */
function _create_event_component( panel_c_event )
{
    var event_top_bar	= _create_event_top_bar();
    var event_grid		= _create_event_grid();

    panel_c_event.add( event_top_bar );
    panel_c_event.add( event_grid );
}

/**
 *	create the toolbar for event panel
 *
 *	return
 *		the toolbar object
 */
function _create_event_top_bar()
{
    var event_top_bar = new Ext.toolbar.Toolbar
    ({
         id:"event_top_bar",
         height:30,
         width:"100%"
    });

    var top_bar_combox 			= create_form_field_combobox( event_top_bar, "事件类型", 50, 150, g_event_type, "type", "local", 60, "serial", 0 )
    var top_bar_search_button 	= create_form_field_button( event_top_bar, "查询", on_search_event );

    event_top_bar.add(
        { xtype:"tbspacer", width:10 },
        top_bar_combox,
        { xtype:"tbspacer", width:10 },
        top_bar_search_button,
        "->"
    );

    event_top_bar.search_combobox	= top_bar_combox;

    return event_top_bar;
}

/**
 *	create the grid for event panel
 *
 *	return
 *		the grid object
 */
function _create_event_grid()
{
    var event_grid = new Ext.grid.Panel
    ({
         id:"event_grid",
         width:"100%",
         flex:1,
         store:g_event,
         columns:[
             {header:"序号", width:50, dataIndex:"serial" },
             {header:"事件类型", width:100, dataIndex:"type" },
             {header:"发生时间", width:120, dataIndex:"datetime" },
             {header:"相关人员", width:100, dataIndex:"user" },
             {header:"事件描述", width:380, dataIndex:"descript" },
         ]
    });

    return event_grid;
}

/**
 *	search tunnel type button handler
 */
function on_search_event()
{
    var eventtype = this.parent.search_combobox.getRawValue();
    g_event.filterBy( function( record )
    {
        if ( "全部" === eventtype )
            return true;
        else
            return (record.get( "type" ) === eventtype );
    });
}
